/*
 * Copyright (c) 2009, The MilkyTracker Team.
 * All rights reserved.
 *
 * Redistribution and use in source and binary forms, with or without
 * modification, are permitted provided that the following conditions are met:
 *
 * - Redistributions of source code must retain the above copyright notice,
 *   this list of conditions and the following disclaimer.
 * - Redistributions in binary form must reproduce the above copyright
 *   notice, this list of conditions and the following disclaimer in the
 *   documentation and/or other materials provided with the distribution.
 * - Neither the name of the <ORGANIZATION> nor the names of its contributors
 *   may be used to endorse or promote products derived from this software
 *   without specific prior written permission.
 *
 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
 * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
 * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
 * POSSIBILITY OF SUCH DAMAGE.
 */

/*
 *  PlayerFAR.h
 *  MilkyPlay core
 *
 *  Created by Peter Barth on Thu Jan 20 2005.
 *
 */
#ifndef __PLAYERFAR_H__
#define __PLAYERFAR_H__

#include "PlayerBase.h"

class PlayerFAR : public PlayerBase
{
    private:
        static mp_uword Freqs[];
        static mp_uword VolTab[];
        static mp_sint32 SinTable[16][128];
        static mp_sint32 mTempo[16];

        // from TRAK.C
        mp_uword OverFlow, OCount, PlayOrder;
        mp_sint32 PitchWheel[16], DestPitch[16], Increment[16], PresPitch[16];
        mp_sint32 VolWheel[16], DestVol[16], VIncrement[16], PresVol[16];
        mp_sint32 RetLeft[16], RetSpc[16], CurSpc[16], RetSmp[16], RetVol[16];
        mp_sint32 OfftCnt[16], RetCnt[16];
        mp_sint32 VibOn[16];
        mp_sint32 VibPtr[16], VibInc[16];
        mp_sint32 CurVols[16];
        mp_ubyte CurBalance[16];
        mp_sint32 CurFreqs[16];
        mp_sint32 CurNote[16];
        mp_sint32 CurEff[16];
        mp_sint32 VibAmp;
        mp_ubyte TempoType;
        mp_sint32 PlayTempo, TempoBend, CurVoice, CurPattern;
        mp_sint32 CurChSmp[16];
        mp_ubyte GrabBuf[64];
    private:
        void CalcTempo();
        void UpdateTempo(mp_sint32 tps);

        void SetFreq(mp_sint32 chn, mp_sint32 freq);
        void SetVolume(mp_sint32 chn, mp_sint32 vol);
        void SetBalance(mp_sint32 chn, mp_ubyte balance);
    protected:
        virtual void clearEffectMemory();
    public:
        PlayerFAR (mp_uint32 frequency);

        virtual ~PlayerFAR ();

        virtual PlayerTypes getType() const {
            return PlayerType_FAR;
        }

        // virtual from mixer class, perform playing here
        virtual void timerHandler(mp_sint32 currentBeatPacket);

        virtual void restart(mp_uint32 startPosition = 0, mp_uint32 startRow = 0, bool resetMixer = true, const mp_ubyte* customPanningTable = NULL, bool playOneRowOnly = false);

        virtual bool grabChannelInfo(mp_sint32 chn, TPlayerChannelInfo& channelInfo) const;
};

#endif